﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FreightSoft.Models;

namespace FreightSoft.Controllers
{
    public class PaymentController : Controller
    {
        private Entities db = new Entities();

        //
        // GET: /Payment/

        public ActionResult Index()
        {
            var customer_order = db.CUSTOMER_ORDER.Where(o => o.STATUS == "Invoiced").Include(c => c.CUSTOMER).Include(c => c.FORWARDER).Include(c => c.PORT).Include(c => c.PORT1);
            return new RazorPDF.PdfResult(customer_order, "Index");
        }

        //
        // GET: /Payment/Details/5

        public ActionResult Details(decimal id = 0)
        {
            CUSTOMER_ORDER customer_order = db.CUSTOMER_ORDER.Find(id);
            if (customer_order == null)
            {
                return HttpNotFound();
            }
            return View(customer_order);
        }

        //
        // GET: /Payment/Create

        public ActionResult Create()
        {
            ViewBag.CUSTOMER_ID = new SelectList(db.CUSTOMERs, "CUSTOMER_ID", "NAME");
            ViewBag.FORWARDER_ID = new SelectList(db.FORWARDERs, "FORWARDER_ID", "NAME");
            ViewBag.SOURCE = new SelectList(db.PORTs, "PORT_ID", "PORT_NAME");
            ViewBag.DESTINATION = new SelectList(db.PORTs, "PORT_ID", "PORT_NAME");
            return View();
        }

        //
        // POST: /Payment/Create

        [HttpPost]
        public ActionResult Create(CUSTOMER_ORDER customer_order)
        {
            if (ModelState.IsValid)
            {
                db.CUSTOMER_ORDER.Add(customer_order);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CUSTOMER_ID = new SelectList(db.CUSTOMERs, "CUSTOMER_ID", "NAME", customer_order.CUSTOMER_ID);
            ViewBag.FORWARDER_ID = new SelectList(db.FORWARDERs, "FORWARDER_ID", "NAME", customer_order.FORWARDER_ID);
            ViewBag.SOURCE = new SelectList(db.PORTs, "PORT_ID", "PORT_NAME", customer_order.SOURCE);
            ViewBag.DESTINATION = new SelectList(db.PORTs, "PORT_ID", "PORT_NAME", customer_order.DESTINATION);
            return View(customer_order);
        }

        //
        // GET: /Payment/Edit/5

        public ActionResult Edit(decimal id = 0)
        {
            CUSTOMER_ORDER customer_order = db.CUSTOMER_ORDER.Find(id);
            if (customer_order == null)
            {
                return HttpNotFound();
            }
            ViewBag.CUSTOMER_ID = new SelectList(db.CUSTOMERs, "CUSTOMER_ID", "NAME", customer_order.CUSTOMER_ID);
            ViewBag.FORWARDER_ID = new SelectList(db.FORWARDERs, "FORWARDER_ID", "NAME", customer_order.FORWARDER_ID);
            ViewBag.SOURCE = new SelectList(db.PORTs, "PORT_ID", "PORT_NAME", customer_order.SOURCE);
            ViewBag.DESTINATION = new SelectList(db.PORTs, "PORT_ID", "PORT_NAME", customer_order.DESTINATION);
            return View(customer_order);
        }

        //
        // POST: /Payment/Edit/5

        [HttpPost]
        public ActionResult Edit(CUSTOMER_ORDER customer_order)
        {
            if (ModelState.IsValid)
            {
                db.Entry(customer_order).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.CUSTOMER_ID = new SelectList(db.CUSTOMERs, "CUSTOMER_ID", "NAME", customer_order.CUSTOMER_ID);
            ViewBag.FORWARDER_ID = new SelectList(db.FORWARDERs, "FORWARDER_ID", "NAME", customer_order.FORWARDER_ID);
            ViewBag.SOURCE = new SelectList(db.PORTs, "PORT_ID", "PORT_NAME", customer_order.SOURCE);
            ViewBag.DESTINATION = new SelectList(db.PORTs, "PORT_ID", "PORT_NAME", customer_order.DESTINATION);
            return View(customer_order);
        }

        //
        // GET: /Payment/Delete/5

        public ActionResult Delete(decimal id = 0)
        {
            CUSTOMER_ORDER customer_order = db.CUSTOMER_ORDER.Find(id);
            if (customer_order == null)
            {
                return HttpNotFound();
            }
            return View(customer_order);
        }

        //
        // POST: /Payment/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(decimal id)
        {
            CUSTOMER_ORDER customer_order = db.CUSTOMER_ORDER.Find(id);
            db.CUSTOMER_ORDER.Remove(customer_order);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}